home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_300
/
317_01
/
builddec.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-06-16
|
29KB
|
838 lines
/* $Id: builddec.c 1.2 90/06/09 18:25:13 marking Exp $
*
NAME
* builddec.c -- build decoding tables for group 3 and group 4 images
*
TYPE
* C source for main program and subroutines
*
SYNOPSIS
* builddec
*
DESCRIPTION
* This program builds tables for decoding group 3 and group 4 encoded
* images. The tables are built as the arrays null_mode [] [],
* null_mode_next_state [] [], horiz_mode [] [], and
* horiz_mode_next_state [] []. The output is C source code which must
* be compiled and linked into a decoding program.
*
RETURNS
* zero if no errors detected, nonzero otherwise
*
LEGAL
* Copyright 1989, 1990 Michael P. Marking, Post Office Box 8039,
* Scottsdale, Arizona 85252-8039. All rights reserved.
*
* License is granted by the copyright holder to distribute and use this
* code without payment of royalties or the necessity of notification as
* long as this notice (all the text under "LEGAL") is included.
*
* Reference: $Id: builddec.c 1.2 90/06/09 18:25:13 marking Exp $
*
* This program is offered without any warranty of any kind. It includes
* no warranty of merchantability or fitness for any purpose. Testing and
* suitability for any use are the sole responsibility of the user.
*
HISTORY
* $Log: builddec.c $
* Revision 1.2 90/06/09 18:25:13 marking
* clean up comments for release
*
* Revision 1.1 89/06/30 17:00:00 marking
* Initial revision
*
*
NOTES
* 1. Since it is expected that this program will be run
* infrequently, there is no attempt at optimization.
* 2. The tables horiz_mode [] [] and horiz_mode_next_state [] []
* are used in both group 3 and group 4 decoding. The tables
* null_mode [] [] and null_mode_next_state [] [] are used only
* in decoding group 4.
* 3. On an XT, this can take around 15 minutes. The progress
* messages it displays let you know it's still alive, but
* otherwise can be ignored.
* 4. Most of the documentation for the tables themselves is in
* the decode routines g3tdecod.c and g4tdecod.c.
*
FILES
* Creates the file "tables.c", which is to be compiled and linked into
* the table-driven decoding routine.
*
PORTABILITY
* Tested under Microsoft C 5.1. Should be fairly portable.
*
SEE ALSO
* g3tdecod.c -- decode group 3 image using tables
* g4tdecod.c -- decode group 4 image using tables
* "Decoding Group 3 Images", C Users Journal, June 1990
*
INFORMATION
* Although there is no support offered with this program, the author will
* endeavor to correct errors. Updates will also be made available from
* time to time.
*
* Contact: Michael P. Marking, Post Office Box 8039, Scottsdale, Arizona
* 85252-8039 USA. Replies are not guaranteed to be swift. Beginning
* July 1990, e-mail may be sent to uunet!ipel!marking.
*
* Also beginning in July 1990, this code will be archived at the
* ipel!phoenix BBS in file g3g4.zoo. The 24-hour telephone number
* for 300/1200/2400 is (602)274-0462. When logging in, specify user
* "public", system "bbs", and password "public".
*
* This code is also available from the C Users Group in volume 317.
*
*/
/*
* standard headers
*/
#include <stddef.h> /* common types and macros */
#include <stdio.h> /* streams and files */
#include <stdlib.h> /* assorted functions, macros, types */
/*
* application
*/
#include "g3g4.h" /* some #defines */
#define INVALID_CODE -1
#define INCOMPLETE_CODE -2
#define EOL_CODE -3
unsigned long append_0 (unsigned long);
unsigned long append_1 (unsigned long);
short black_run_length (unsigned long);
short search_run_length_table (unsigned long, long *);
short white_run_length (unsigned long);
unsigned long append_0 (unsigned long prefix)
{
return (prefix + 0x10000);
}
unsigned long append_1 (unsigned long prefix)
{
unsigned short prefix_length;
static unsigned short prefix_mask [16] = {0x8000, 0x4000, 0x2000, 0x1000,
0x0800, 0x0400, 0x0200, 0x0100, 0x0080, 0x0040, 0x0020, 0x0010, 0x0008,
0x0004, 0x0002, 0x0001};
prefix_length = 0xFF & (unsigned short) (prefix >> 16);
return (prefix + 0x10000 + prefix_mask [prefix_length]);
}
short search_run_length_table (unsigned long prefix, long *p_table)
{
short table_offset = 0;
long prefix_length, prefix_value;
prefix_length = 0xFF & (prefix >> 16);
prefix_value = 0xFFFF & prefix;
while (p_table [table_offset])
{
if (p_table [table_offset] == prefix_length
&& p_table [table_offset + 1] == prefix_value)
return ((short) p_table [table_offset + 2]);
table_offset += 3; /* move on to next entry */
}
return (INCOMPLETE_CODE); /* no entry found in table */
}
short white_run_length (unsigned long prefix)
{
static long code_table [] =
{
8, 0x3500, 0, /* 0011 0101 */
6, 0x1C00, 1, /* 0001 11 */
4, 0x7000, 2, /* 0111 */
4, 0x8000, 3, /* 1000 */
4, 0xB000, 4, /* 1011 */
4, 0xC000, 5, /* 1100 */
4, 0xE000, 6, /* 1110 */
4, 0xF000, 7, /* 1111 */
5, 0x9800, 8, /* 1001 1 */
5, 0xA000, 9, /* 1010 0 */
5, 0x3800, 10, /* 0011 1 */
5, 0x4000, 11, /* 0100 0 */
6, 0x2000, 12, /* 0010 00 */
6, 0x0C00, 13, /* 0000 11 */
6, 0xD000, 14, /* 1101 00 */
6, 0xD400, 15, /* 1101 01 */
6, 0xA800, 16, /* 1010 10 */
6, 0xAC00, 17, /* 1010 11 */
7, 0x4E00, 18, /* 0100 111 */
7, 0x1800, 19, /* 0001 100 */
7, 0x1000, 20, /* 0001 000 */
7, 0x2E00, 21, /* 0010 111 */
7, 0x0600, 22, /* 0000 011 */
7, 0x0800, 23, /* 0000 100 */
7, 0x5000, 24, /* 0101 000 */
7, 0x5600, 25, /* 0101 011 */
7, 0x2600, 26, /* 0010 011 */
7, 0x4800, 27, /* 0100 100 */
7, 0x3000, 28, /* 0011 000 */
8, 0x0200, 29, /* 0000 0010 */
8, 0x0300, 30, /* 0000 0011 */
8, 0x1A00, 31, /* 0001 1010 */
8, 0x1B00, 32, /* 0001 1011 */
8, 0x1200, 33, /* 0001 0010 */
8, 0x1300, 34, /* 0001 0011 */
8, 0x1400, 35, /* 0001 0100 */
8, 0x1500, 36, /* 0001 0101 */
8, 0x1600, 37, /* 0001 0110 */
8, 0x1700, 38, /* 0001 0111 */
8, 0x2800, 39, /* 0010 1000 */
8, 0x2900, 40, /* 0010 1001 */
8, 0x2A00, 41, /* 0010 1010 */
8, 0x2B00, 42, /* 0010 1011 */
8, 0x2C00, 43, /* 0010 1100 */
8, 0x2D00, 44, /* 0010 1101 */
8, 0x0400, 45, /* 0000 0100 */
8, 0x0500, 46, /* 0000 0101 */
8, 0x0A00, 47, /* 0000 1010 */
8, 0x0B00, 48, /* 0000 1011 */
8, 0x5200, 49, /* 0101 0010 */
8, 0x5300, 50, /* 0101 0011 */
8, 0x5400, 51, /* 0101 0100 */
8, 0x5500, 52, /* 0101 0101 */
8, 0x2400, 53, /* 0010 0100 */
8, 0x2500, 54, /* 0010 0101 */
8, 0x5800, 55, /* 0101 1000 */
8, 0x5900, 56, /* 0101 1001 */
8, 0x5A00, 57, /* 0101 1010 */
8, 0x5B00, 58, /* 0101 1011 */
8, 0x4A00, 59, /* 0100 1010 */
8, 0x4B00, 60, /* 0100 1011 */
8, 0x3200, 61, /* 0011 0010 */
8, 0x3300, 62, /* 0011 0011 */
8, 0x3400, 63, /* 0011 0100 */
5, 0xD800, 64, /* 1101 1 */
5, 0x9000, 128, /* 1001 0 */
6, 0x5C00, 192, /* 0101 11 */
7, 0x6E00, 256, /* 0110 111 */
8, 0x3600, 320, /* 0011 0110 */
8, 0x3700, 384, /* 0011 0111 */
8, 0x6400, 448, /* 0110 0100 */
8, 0x6500, 512, /* 0110 0101 */
8, 0x6800, 576, /* 0110 1000 */
8, 0x6700, 640, /* 0110 0111 */
9, 0x6600, 704, /* 0110 0110 0 */
9, 0x6680, 768, /* 0110 0110 1 */
9, 0x6900, 832, /* 0110 1001 0 */
9, 0x6980, 896, /* 0110 1001 1 */
9, 0x6A00, 960, /* 0110 1010 0 */
9, 0x6A80, 1024, /* 0110 1010 1 */
9, 0x6B00, 1088, /* 0110 1011 0 */
9, 0x6B80, 1152, /* 0110 1011 1 */
9, 0x6C00, 1216, /* 0110 1100 0 */
9, 0x6C80, 1280, /* 0110 1100 1 */
9, 0x6D00, 1344, /* 0110 1101 0 */
9, 0x6D80, 1408, /* 0110 1101 1 */
9, 0x4C00, 1472, /* 0100 1100 0 */
9, 0x4C80, 1536, /* 0100 1100 1 */
9, 0x4D00, 1600, /* 0100 1101 0 */
6, 0x6000, 1664, /* 0110 00 */
9, 0x4D80, 1728, /* 0100 1101 1 */
11, 0x0100, 1792, /* 0000 0001 000 */
11, 0x0180, 1856, /* 0000 0001 100 */
11, 0x